﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Course.Controllers;
using Course.Models;

namespace Course.Views
{
    public partial class LogIn : Form
    {
        private LogInController _controller;
        public LogInController Controller{
            get {
                return _controller;
            }
            set {
                _controller = value;
                this.textBox1.DataBindings.Add("Text",Controller.Model,"UserId");
                this.textBox2.DataBindings.Add("Text",Controller.Model,"Password");
                this.comboBox1.DataBindings.Add("SelectedIndex",Controller.Model,"eRole");
            }
        }
        //DataClasseDataContext context = new DataClasseDataContext();
        public LogIn()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
			string id=Controller.LogIn();
            if (id==null)
            {
                MessageBox.Show("Failure");
            }
            else {
                StuHomeController controller = new StuHomeController(new StuHome(), id);
                this.Hide();
                controller.View.Show();
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void LogIn_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            
            RegisterController controller = new RegisterController(new Register());
            controller.View.Show();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
